home *** CD-ROM | disk | FTP | other *** search
/ Programmer Power Tools / Programmer Power Tools.iso / progjrn / pj_7_2.arc / PMDEV1.ARC / PMAUXFN.C < prev    next >
Text File  |  1988-12-03  |  4KB  |  145 lines

  1. /*
  2.  * PMAUXFN - function support module for PMAUX
  3.  *
  4.  * Written by Bill Hall
  5.  * 3665  Benton Street, #66
  6.  * Santa Clara, CA 95051
  7.  *
  8.  */
  9.  
  10. #define INCL_PM
  11. #include <os2.h>
  12. #include <stdlib.h>
  13. #include <string.h>
  14. #include <ttycls.h>
  15. #include "pmaux.h"
  16.  
  17. /* set the window handle (might be NULL) into OS2.ini */
  18. BOOL SetOS2Ini(HWND hWnd)
  19. {
  20.     char buf[30];
  21.     return(WinWriteProfileString(hAB,szAppName,"hWnd",ltoa((LONG)hWnd,buf,10)));
  22. }
  23.  
  24. /* respond to menu commands */
  25. void NEAR WndCommand(HWND hWnd, USHORT wParam)
  26. {
  27.  
  28.     HWND hMenu;
  29.  
  30.     switch (wParam) {
  31.         case IDM_CRONLF:
  32.         MWnd.CRonLF = (MWnd.CRonLF ? FALSE : TRUE);    /* toggle parameter */
  33.         hMenu = WinWindowFromID(hwndFrame, FID_MENU);  /* get menu */
  34.       /* set or remove check mark on menu */
  35.          WinSendMsg(hMenu, MM_SETITEMATTR, MPFROM2SHORT(wParam, TRUE),
  36.               MPFROM2SHORT(MIA_CHECKED, MWnd.CRonLF ? MIA_CHECKED : 0));
  37.         break;
  38.  
  39.     case IDM_ABOUT:        /* display about box */
  40.         WinDlgBox(HWND_DESKTOP, hWnd, AboutBoxProc, NULL, DT_ABOUT, NULL);
  41.         break;
  42.     }
  43. }
  44.  
  45. /* send the received buffer to the display */
  46. void NEAR DispatchString(HWND hWnd, MPARAM mp1, MPARAM mp2)
  47. {
  48.  
  49. #define LBUFLEN 80
  50.  
  51.     BYTE buf[LBUFLEN];
  52.     int len, i, count;
  53.     BYTE FAR *bufptr;
  54.     SEL sel;
  55.  
  56.     len = (int)LOUSHORT(mp1);    /* read the length */
  57.     sel = (SEL)LOUSHORT(mp2);    /* get the selector of the shared buffer */
  58.     bufptr = MAKEP(sel,0);    /* make it into a pointer */
  59.  
  60.     if (DosGetSeg(sel) == 0) {    /* access the shared buffer */
  61.     while (len > 0) { /* read and dispatch each part of buffer until done */                                
  62.         count = min(len, LBUFLEN);        
  63.             for (i = 0; i < count; i++)
  64.             buf[i] = *bufptr++;
  65.             TTYDisplay(&MWnd, (short)count, buf);
  66.         len -= count;
  67.     }
  68.     }
  69.     else    /* something wrong, ring the bell */
  70.     WinAlarm(HWND_DESKTOP, WA_WARNING);
  71. }
  72.  
  73. /* repaint the window if needed */
  74. void NEAR MainWndPaint(HWND hWnd, HPS hPS, short top, short bottom)
  75. {
  76.  
  77. /* 
  78.   If Microsoft ever gets WinQueryWindowPos working correctly, then
  79.   replace the line 'if (WindowIsIconic(hWnd))' with the following: 
  80. */
  81. /*
  82.     SWP swp;
  83.  
  84.     WinQueryWindowPos(hWnd, &swp);
  85.  
  86.     if ((swp.fs & SWP_MINIMIZE) && (!(swp.fs & SWP_MAXIMIZE))) {
  87. */
  88.  
  89.     if (WindowIsIconic(hWnd)) {
  90.         POINTL pt;
  91.     pt.x = 0;
  92.       pt.y = 0;
  93.     GpiMove(hPS, (PPOINTL)&pt);
  94.     pt.x = xIconsize-1;
  95.     pt.y = yIconsize-1;
  96.         GpiBox(hPS, 2L, (PPOINTL)&pt, 0L, 0L);
  97.         pt.x = 0;
  98.         pt.y = 2 * (yIconsize - MWnd.CHeight) / 3;
  99.         GpiCharStringAt( hPS, (PPOINTL)&pt, (LONG)strlen(szIcon), (PCH)szIcon);
  100.     }
  101.     else
  102.     TTYWndPaint(&MWnd, hPS, top, bottom);
  103. }
  104.  
  105. /* 
  106.  * Return TRUE if main window is iconic.
  107.  * This kludge is needed since WinQueryWindowPos is not yet fully implemented.
  108.  */
  109. BOOL NEAR WindowIsIconic(HWND hWnd)
  110. {
  111.  
  112.     RECTL cRect;
  113.  
  114.   /* get the current window client rectangle */
  115.     WinQueryWindowRect(hWnd, (PRECTL)&cRect);
  116.  
  117.   /* compare with size when window is iconic */
  118.     if ((cRect.xRight == xIconsize) && (cRect.yTop == yIconsize))
  119.     return TRUE;
  120.  
  121.     return FALSE;
  122. }
  123.  
  124. /* simple procedure to handle the about box */
  125. MRESULT EXPENTRY AboutBoxProc(HWND hDlg, USHORT msg, MPARAM mp1, MPARAM mp2)
  126. {
  127.  
  128.     switch (msg) {
  129.  
  130.     case WM_COMMAND:
  131.         switch(COMMANDMSG(&msg)->cmd) {
  132.         case DID_OK:
  133.             WinDismissDlg (hDlg, TRUE);
  134.             break;
  135.         default:
  136.             break;
  137.         }
  138.         break;
  139.  
  140.     default:
  141.         return WinDefDlgProc(hDlg, msg, mp1, mp2);
  142.     }
  143.     return FALSE;
  144. }
  145.